<extend name="Base/common"/>
<block name="style">
    <style type="text/css">
    	.upload-pre-item img {
		  min-width: 250px;
		  max-width: 250px;
		  max-height: 300px;
		  border-radius: 15px;
		  padding: 2px;
		}
		.uploadcover {
		  color: #666;
		  background-color: #fff;
		  border-color: #4f8ad0;
		  display: inline-block;
		  margin-bottom: 0;
		  font-weight: normal;
		  text-align: center;
		  vertical-align: middle;
		  cursor: pointer;
		  background-image: none;
		  border: 1px solid rgba(0, 0, 0, 0);
		  white-space: nowrap;
		  font-size: 12px;
		  -webkit-user-select: none;
		  -moz-user-select: none;
		  -ms-user-select: none;
		  position: absolute;
		}
    </style>
</block>
<block name="body">
<div class="aw-publish">
    <div class="aw-publish-header">
		<h1 style="padding:40px;">
			<if condition="$isEdit">修改话题<else/>新建话题</if>
		</h1>
	</div>
	<div class="aw-publish-body clearfix">
		<form action="{:U('Group/Index/doEdit')}" method="post" class="ajax-form" id="edit-article-form" >
        <input type="hidden" name="post_id" value="{$post.id}"/>
		<input type="hidden" id="isEdit" value="{$isEdit}">
		<input type="hidden" id="category" name="category" value="{$post['cate_id']}">

		<div class="col-md-6" style="padding: 0 30px 0px 100px;">
			<span class="topic-tag " onclick="$('#category').val('1');$('.topic-type').removeClass('active');$(this).find('a').addClass('active');$('#youku').show();">
				<a class="topic-type <if condition="$post['cate_id'] eq 1">active</if>">视频话题</a>
			</span>
		</div>
		<div class="col-md-6" style="padding: 0px 100px 0px 20px;">
			<span class="topic-tag " onclick="$('#category').val('2');$('.topic-type').removeClass('active');$(this).find('a').addClass('active');$('#youku').hide();">
				<a class="topic-type <if condition="$post['cate_id'] eq 2">active</if>">图文话题</a>
			</span>
		</div>
		<div class="clearfix"></div>
		<div class="col-md-6 aw-main-content">
			<div class="aw-mod aw-mod-publish">
				<div class="mod-body">
					<if condition="$post['cate_id'] eq 1">
					<div id="youku" style="display: ;">
					<else />
					<div id="youku" style="display: none;">
					</if>
					<h3 class="upload-youku">温馨提示：视频上传功能由优酷提供合作技术支持</h3>
					<div class="aw-mod upload-youku">
						<div style="margin-bottom: 10px;"><a href="#frm-post-popup" class="open-popup-link"><img src="__THEME_PUBLIC__/images/youku.png" /></a></div>
						<input id="url" name="video_url" type="text" class="form-control" value="{$post.video_url}" placeholder="输入以http://开头以.swf结尾的视频地址"/>
					</div>
					</div>
					<h3>上传封面：<span style="color:#ffaf86">支持jpg、png、gif等图片格式，请勿上传违法图片！</span></h3>
					<div class="aw-publish-title">
						<input type="file" id="upload_picture_cover">
                        <div class="upload-img-box" style="width:208px;margin-top: 10px;">
                            <if condition="$isEdit">
                            <div class="upload-pre-item"><img src="{$post.cover}"></div>
                            <else/>
                            <div style="background:url(__THEME_PUBLIC__/images/img50.png) #fff no-repeat center;height:118px;border-radius: 15px;"></div>
                            </if>
                        </div>
                        <input type="hidden" name="cover" id="cover_id_cover" value="{$post.cover}"/>
					</div>
					<h3>标题 (必填)：</h3>
					<div class="aw-publish-title">
						<div>
							<input id="title" type="text" name="title" placeholder="{:L('_TITLE_')}" value="{$post.title}" class="form-control"/>
						</div>
					</div>
					<h3>描述：</h3>
					<div class="aw-mod aw-editor-box">
						<div class="mod-head">
							<div class="wmd-panel">
								<textarea name="summary" class="form-control" id="inputDescription" placeholder="填写关于话题的简单介绍">{$post.summary}</textarea>
							</div>
						</div>
					</div>
					<h3>发布到以下树丛：</h3>
					<div class="aw-topic-bar" data-type="publish">
						<input id="group" name="group" type="text" class="form-control" value="{$group.id|get_group_name}" placeholder="选择下方加入的树丛" readonly="true"/>
						<input id="group_id" name="group_id" type="hidden" value="{$group.id}" />
					</div>

					<h3>我加入的树丛：</h3>
					<div class="aw-topic-bar">
						<div class="topic-bar clearfix">	
							<volist name="groups" id="vo">
							<span class="topic-tag" onclick="$('#group').val('{$vo.title}');$('#group_id').val('{$vo.id}');$('.topic-bar').find('a').removeClass('active');$(this).find('a').addClass('active');">
								<a class="text <if condition="$group['id'] eq $vo['id']">active</if>">{$vo.title}</a>
							</span>
							</volist>
						</div>
					</div>
					<h3>分享志同道合的树友：</h3>
					<div class="aw-friend">
						<ul>
				
						</ul>
					</div>
				</div>
			</div>
		</div>
		<div class="col-md-6 aw-side-bar">
			<div class="friendlist">
				<h2>选择树友列表</h2>
				<div class="bd" style="height:500px">
					<ul>
						<volist name="friends" id="vo">
						<li>
							<div class="img">
							<a href="javascript:;"><img src="{$vo.user.avatar64}" alt="{$vo.user.nickname}" /></a>
							</div>
							<h3><a href="javascript:;">{$vo.user.nickname}</a></h3>
							<em class="addbtn" onclick="addfriend($(this),$(this).parents('li').find('img').attr('src'),{$vo.user.id})"></em>
						</li>
						</volist>
					</ul>
				</div>
			</div>
			
			
		</div>
		<div class="clearfix"></div>
		<div class="col-md-12" style="padding:0 100px;">
			<php>
                $config="toolbars:[['insertimage','|','bold','italic','underline','fontsize','forecolor','fontfamily','backcolor','|','link','emotion','scrawl','attachment','insertcode','wordimage','|','source']]";</php>
            </php>
            {:W('Common/Ueditor/editor',array('contentEditor','content',$post['content'],'100%','250px',$config))}
		</div>
		<div class="clearfix"></div>
		<div class="col-md-12 text-center" style="margin-top:30px;">
				<button id="submit-button" type="submit" class="btn btn-primary" style="width:300px;height:50px;background-color: #5ac994;border:none;" ><if condition="$isEdit">修改话题<else/>创建话题</if></button>
		</div>
		</form>
	</div>
</div>

<include file="_box"/>

</block>
<block name="script">
        <script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
        <script>
            function addfriend(selector,img,uid){
				var fridennum=$(".aw-friend").find('li').length;
				if(fridennum<6){
					$('.aw-friend').find('ul').append(' <li id="'+uid+'"><img src="'+ img +'" /><input type=\'hidden\' value="'+ uid +'" name="friends[]"></li>');
					selector.parent('li').addClass('selected');
					selector.attr('onclick','cannelfriend($(this),'+uid+')');
				}else{
					alert('邀请人数超过指定数量！');
				}
			}
			function cannelfriend(selector,uid){
				$('.aw-friend').find('#'+uid+'').remove();
				selector.parent('li').removeClass('selected');
				selector.attr('onclick','addfriend($(this),$(this).parents(\'li\').find(\'img\').attr(\'src\'),'+uid+')');
			}
        </script>

        <script type="text/javascript">
            //上传图片
            /* 初始化上传插件 */
            $("#upload_picture_cover").uploadify({
                "height"          : 30,
                "swf"             : "__STATIC__/uploadify/uploadify.swf",
                "fileObjName"     : "download",
                "buttonText"      : "上传封面",
                "buttonClass":"uploadcover",
                "uploader"        : "{:U('Core/File/uploadPicture',array('session_id'=>session_id()))}",
                "width"           : 100,
                'removeTimeout'	  : 1,
                'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
                "onUploadSuccess" : uploadPicturecover,
                'overrideEvents':['onUploadProgress','onUploadComplete','onUploadStart','onSelect'],
                'onFallback' : function() {
                    alert('未检测到兼容版本的Flash.');
                }, 'onUploadProgress': function (file, bytesUploaded, bytesTotal, totalBytesUploaded, totalBytesTotal) {
                    $("#cover_id_cover").parent().find('.upload-img-box').html(totalBytesUploaded + ' bytes uploaded of ' + totalBytesTotal + ' bytes.');
                },'onUploadComplete' : function(file) {
                    //alert('The file ' + file.name + ' finished processing.');
                },'onUploadStart' : function(file) {
                    //alert('Starting to upload ' + file.name);
                },'onQueueComplete' : function(queueData) {
                    // alert(queueData.uploadsSuccessful + ' files were successfully uploaded.');
                }
            });
            function uploadPicturecover(file, data){
                var data = $.parseJSON(data);
                var src = '';
                if(data.status){
                    
                    src = data.url ||  data.path
                    $("#cover_id_cover").val(src);
                    $('.upload-img-box').html(
                            '<div class="upload-pre-item"><img src="' + src + '"/></div>'
                    );
                } else {
                    toast.error('形象上传失败。','温馨提示');
                }
            }
        </script>
</block>
